package com.neu.dao;

import com.neu.entity.Admin;

import com.neu.entity.Book;
import com.neu.entity.Params;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface AdminDao extends Mapper<Admin> {

    //基于注解的方式
    @Select("select * from admin")
    List<Admin> getUser();

    List<Admin> findBySearch(@Param("params") Params params);

    @Select("select * from admin where name=#{name} limit 1")
    Admin findByName(@Param("name") String name);

    @Select("select * from admin where name=#{name} and password=#{password} limit 1")
    Admin findByNameAndPassword(@Param("name") String name,@Param("password") String password);


    List<Admin> findBySearchTutor(@Param("params") Params params);

    void updateTutor(Admin admin);

    void updatePassword(Admin admin);
    @Select("select phone from admin where name = #{name}")
    String getPhoneByName(Admin admin);
    @Select("select email from admin where name = #{name}")
    String getEmailByName(Admin admin);

    @Select("select admin.*,type.name as typeName from admin  join type on admin.typeId = type.id")
    List<Admin> findAll();

    @Update("update admin set content = #{content} where id = #{id}")
    void updateAdminContent(Admin admin);

    @Update("update admin set content = #{content} where name = #{name}")
    void updateTutorContent(Admin admin);

    @Update("update admin set content = concat(IFNULL(content, ''), #{content}) where id = #{id}")
    void insertTutorContent(Admin admin);
}
